package com.ruoyi.DegreeCommit.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.DegreeCommit.mapper.DegreeCommitMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.DegreeCommit.domain.DegreeCommit;
import com.ruoyi.DegreeCommit.service.IDegreeCommitService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * DegreeCommitController
 * 
 * @author ruoyi
 * @date 2025-04-23
 */
@RestController
@RequestMapping("/DegreeCommit/commit")
public class DegreeCommitController extends BaseController
{
    @Autowired
    private IDegreeCommitService degreeCommitService;

    @Autowired
    private DegreeCommitMapper degreeCommitMapper;

    /**
     * 查询DegreeCommit列表
     */
    @PreAuthorize("@ss.hasPermi('DegreeCommit:commit:list')")
    @GetMapping("/list")
    public TableDataInfo list(DegreeCommit degreeCommit)
    {
        startPage();
        List<DegreeCommit> list = degreeCommitService.selectDegreeCommitList(degreeCommit);
        return getDataTable(list);
    }


    /**
     * 导出DegreeCommit列表
     */
    @PreAuthorize("@ss.hasPermi('DegreeCommit:commit:export')")
    @Log(title = "DegreeCommit", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DegreeCommit degreeCommit)
    {
        List<DegreeCommit> list = degreeCommitService.selectDegreeCommitList(degreeCommit);
        ExcelUtil<DegreeCommit> util = new ExcelUtil<DegreeCommit>(DegreeCommit.class);
        util.exportExcel(response, list, "DegreeCommit数据");
    }

    /**
     * 获取DegreeCommit详细信息
     */
    @PreAuthorize("@ss.hasPermi('DegreeCommit:commit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(degreeCommitService.selectDegreeCommitById(id));
    }

    /**
     * 新增DegreeCommit
     */
    @PreAuthorize("@ss.hasPermi('DegreeCommit:commit:add')")
    @Log(title = "DegreeCommit", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DegreeCommit degreeCommit)
    {
        return toAjax(degreeCommitService.insertDegreeCommit(degreeCommit));
    }

    /**
     * 修改DegreeCommit
     */
//    @PreAuthorize("@ss.hasPermi('DegreeCommit:commit:edit')")
    @Log(title = "DegreeCommit", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DegreeCommit degreeCommit)
    {
        return toAjax(degreeCommitService.updateDegreeCommit(degreeCommit));
    }

    /**
     * 删除DegreeCommit
     */
    @PreAuthorize("@ss.hasPermi('DegreeCommit:commit:remove')")
    @Log(title = "DegreeCommit", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(degreeCommitService.deleteDegreeCommitByIds(ids));
    }

    //根据用户ID 查询提交信息
    @GetMapping("/byUId")
    public AjaxResult listByUId()
    {
        startPage();
        List<DegreeCommit> list = degreeCommitMapper.selectByUId(getUserId());
        return success(list);
    }
}
